﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RibbonEditor.LocLabels;

namespace RibbonEditor.Controls.LocLabels
{
    public partial class LocLabelControl : UserControl, IControlRulable
    {
        private LocLabel localizedLabel;

        internal LocLabel LocalizedLabel
        {
            get { return localizedLabel; }
            set { localizedLabel = value; }
        }

        public LocLabelControl()
        {
            InitializeComponent();

            this.localizedLabel = new LocLabel();
        }

        public LocLabelControl(LocLabel locLabel)
            : this()
        {
            this.localizedLabel = locLabel;
            this.FillControls();
        }

        public void FillControls()
        {
            try
            {
                this.stringControl1.Value = this.localizedLabel.Id;
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void Save()
        {
            try
            {
                this.localizedLabel.Id = this.stringControl1.Value;

                UserControlHelper.CleanDirtyFields(this);
            }
            catch (Exception error)
            {
                MessageBox.Show(this, "An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #region IControlRulable Members

        public void BuildObjectXml(System.Xml.XmlNode parentNode)
        {
            try
            {
                this.localizedLabel.AddNode(parentNode);
            }
            catch (Exception error)
            {
                MessageBox.Show(this, "An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #endregion
    }
}
